from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-12-04 14:03:36.616469
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 04, Dec, 2021
Time: 14:03:42
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.3490
Nobs: 495.000 HQIC: -47.8134
Log likelihood: 5676.72 FPE: 1.27234e-21
AIC: -48.1135 Det(Omega_mle): 1.06274e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.382324 0.082393 4.640 0.000
L1.Burgenland 0.094437 0.044460 2.124 0.034
L1.Kärnten -0.116199 0.022805 -5.095 0.000
L1.Niederösterreich 0.165808 0.092222 1.798 0.072
L1.Oberösterreich 0.127934 0.093549 1.368 0.171
L1.Salzburg 0.281718 0.047692 5.907 0.000
L1.Steiermark 0.016125 0.061610 0.262 0.794
L1.Tirol 0.107619 0.049710 2.165 0.030
L1.Vorarlberg -0.084774 0.043792 -1.936 0.053
L1.Wien 0.032145 0.083702 0.384 0.701
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.026125 0.182904 0.143 0.886
L1.Burgenland -0.052018 0.098695 -0.527 0.598
L1.Kärnten 0.036389 0.050624 0.719 0.472
L1.Niederösterreich -0.224427 0.204723 -1.096 0.273
L1.Oberösterreich 0.477424 0.207667 2.299 0.022
L1.Salzburg 0.311915 0.105871 2.946 0.003
L1.Steiermark 0.099182 0.136767 0.725 0.468
L1.Tirol 0.308529 0.110351 2.796 0.005
L1.Vorarlberg 0.008612 0.097214 0.089 0.929
L1.Wien 0.019198 0.185809 0.103 0.918
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.231485 0.041931 5.521 0.000
L1.Burgenland 0.090516 0.022626 4.001 0.000
L1.Kärnten -0.004782 0.011606 -0.412 0.680
L1.Niederösterreich 0.219622 0.046933 4.679 0.000
L1.Oberösterreich 0.165944 0.047608 3.486 0.000
L1.Salzburg 0.035406 0.024271 1.459 0.145
L1.Steiermark 0.025154 0.031354 0.802 0.422
L1.Tirol 0.075507 0.025298 2.985 0.003
L1.Vorarlberg 0.056434 0.022287 2.532 0.011
L1.Wien 0.106488 0.042597 2.500 0.012
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.167408 0.040799 4.103 0.000
L1.Burgenland 0.043043 0.022015 1.955 0.051
L1.Kärnten -0.012545 0.011292 -1.111 0.267
L1.Niederösterreich 0.146891 0.045666 3.217 0.001
L1.Oberösterreich 0.345472 0.046323 7.458 0.000
L1.Salzburg 0.099616 0.023616 4.218 0.000
L1.Steiermark 0.106754 0.030508 3.499 0.000
L1.Tirol 0.086323 0.024615 3.507 0.000
L1.Vorarlberg 0.054178 0.021685 2.498 0.012
L1.Wien -0.037362 0.041447 -0.901 0.367
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169532 0.078723 2.154 0.031
L1.Burgenland -0.041729 0.042479 -0.982 0.326
L1.Kärnten -0.036572 0.021789 -1.678 0.093
L1.Niederösterreich 0.124367 0.088114 1.411 0.158
L1.Oberösterreich 0.186085 0.089382 2.082 0.037
L1.Salzburg 0.254334 0.045568 5.581 0.000
L1.Steiermark 0.071877 0.058865 1.221 0.222
L1.Tirol 0.130992 0.047496 2.758 0.006
L1.Vorarlberg 0.106017 0.041842 2.534 0.011
L1.Wien 0.038765 0.079974 0.485 0.628
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.082336 0.062374 1.320 0.187
L1.Burgenland 0.015044 0.033657 0.447 0.655
L1.Kärnten 0.051548 0.017264 2.986 0.003
L1.Niederösterreich 0.176853 0.069815 2.533 0.011
L1.Oberösterreich 0.338791 0.070819 4.784 0.000
L1.Salzburg 0.049965 0.036104 1.384 0.166
L1.Steiermark -0.007006 0.046640 -0.150 0.881
L1.Tirol 0.122647 0.037632 3.259 0.001
L1.Vorarlberg 0.058745 0.033152 1.772 0.076
L1.Wien 0.112896 0.063365 1.782 0.075
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174082 0.075766 2.298 0.022
L1.Burgenland 0.011299 0.040883 0.276 0.782
L1.Kärnten -0.061046 0.020970 -2.911 0.004
L1.Niederösterreich -0.114458 0.084804 -1.350 0.177
L1.Oberösterreich 0.231063 0.086024 2.686 0.007
L1.Salzburg 0.037453 0.043856 0.854 0.393
L1.Steiermark 0.264514 0.056654 4.669 0.000
L1.Tirol 0.489601 0.045712 10.711 0.000
L1.Vorarlberg 0.071381 0.040270 1.773 0.076
L1.Wien -0.100828 0.076969 -1.310 0.190
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.139353 0.083742 1.664 0.096
L1.Burgenland -0.013040 0.045187 -0.289 0.773
L1.Kärnten 0.064140 0.023178 2.767 0.006
L1.Niederösterreich 0.170236 0.093731 1.816 0.069
L1.Oberösterreich -0.074633 0.095080 -0.785 0.432
L1.Salzburg 0.221581 0.048473 4.571 0.000
L1.Steiermark 0.135091 0.062618 2.157 0.031
L1.Tirol 0.050175 0.050524 0.993 0.321
L1.Vorarlberg 0.142658 0.044509 3.205 0.001
L1.Wien 0.168222 0.085072 1.977 0.048
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.456738 0.046253 9.875 0.000
L1.Burgenland -0.000782 0.024958 -0.031 0.975
L1.Kärnten -0.013144 0.012802 -1.027 0.305
L1.Niederösterreich 0.177325 0.051770 3.425 0.001
L1.Oberösterreich 0.267893 0.052515 5.101 0.000
L1.Salzburg 0.019192 0.026773 0.717 0.473
L1.Steiermark -0.014665 0.034585 -0.424 0.672
L1.Tirol 0.069375 0.027906 2.486 0.013
L1.Vorarlberg 0.056402 0.024583 2.294 0.022
L1.Wien -0.016581 0.046987 -0.353 0.724
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.026131 0.090959 0.154214 0.137971 0.063515 0.081897 0.015322 0.207649
Kärnten 0.026131 1.000000 -0.037506 0.127141 0.047374 0.072994 0.456518 -0.082206 0.094071
Niederösterreich 0.090959 -0.037506 1.000000 0.275964 0.096150 0.252967 0.050757 0.141152 0.244029
Oberösterreich 0.154214 0.127141 0.275964 1.000000 0.189236 0.284543 0.161264 0.124662 0.177840
Salzburg 0.137971 0.047374 0.096150 0.189236 1.000000 0.119933 0.060362 0.109374 0.062498
Steiermark 0.063515 0.072994 0.252967 0.284543 0.119933 1.000000 0.131961 0.087619 0.004068
Tirol 0.081897 0.456518 0.050757 0.161264 0.060362 0.131961 1.000000 0.063064 0.128436
Vorarlberg 0.015322 -0.082206 0.141152 0.124662 0.109374 0.087619 0.063064 1.000000 -0.011618
Wien 0.207649 0.094071 0.244029 0.177840 0.062498 0.004068 0.128436 -0.011618 1.000000